
using System;
using System.Collections;
using System.Web.UI.WebControls;
using System.Web;

namespace Com.Phyfun.Business
{
    #region Lang

    /// <summary>
    /// Lang object for NHibernate mapped table 'Lang'.
    /// </summary>
    public class Lang : BizObject
    {
        #region Member Variables

        protected int _id;
        protected string _langName;
        protected string _icon;
        protected DateTime _pubDate;
        protected string _desc;
        protected int _flag;
        protected static String _sortExpression = "Id";
        protected static SortDirection _sortDirection = SortDirection.Ascending;

        #endregion

        #region Constructors

        public Lang() { }

        public Lang(int id) { if (id != 0)ObjectBroker.Load(this, id); }

        public Lang(string langName, string icon, DateTime pubDate, string desc, int flag)
        {
            this._langName = langName;
            this._icon = icon;
            this._pubDate = pubDate;
            this._desc = desc;
            this._flag = flag;
        }

        #endregion

        #region Public Properties

        public virtual int Id
        {
            get { return _id; }
            set { _id = value; }
        }

        public virtual string LangName
        {
            get { return _langName; }
            set
            {
                if (value != null && value.Length > 100)
                    throw new ArgumentOutOfRangeException("Invalid value for LangName", value, value.ToString());
                _langName = value;
            }
        }

        public virtual string Icon
        {
            get { return _icon; }
            set
            {
                if (value != null && value.Length > 200)
                    throw new ArgumentOutOfRangeException("Invalid value for Icon", value, value.ToString());
                _icon = value;
            }
        }

        public virtual DateTime PubDate
        {
            get { return _pubDate; }
            set { _pubDate = value; }
        }

        public virtual string Desc
        {
            get { return _desc; }
            set
            {
                if (value != null && value.Length > 200)
                    throw new ArgumentOutOfRangeException("Invalid value for Desc", value, value.ToString());
                _desc = value;
            }
        }

        public virtual int Flag
        {
            get { return _flag; }
            set { _flag = value; }
        }

        public static String SortExpression
        {
            get { return _sortExpression; }
            set { _sortExpression = value; }
        }

        public static SortDirection SortDirection
        {
            get { return _sortDirection; }
            set { _sortDirection = value; }
        }

        public virtual string IconFullPath
        {
            get
            {
                return HttpContext.Current.Request.ApplicationPath + Icon;
            }
        }
        #endregion

        #region IComparable Methods
        public virtual int CompareTo(object obj)
        {
            if (!(obj is Lang))
                throw new InvalidCastException("This object is not of type Lang");

            int relativeValue;
            switch (SortExpression)
            {
                case "Id":
                    relativeValue = this.Id.CompareTo(((Lang)obj).Id);
                    break;
                case "Lang":
                    relativeValue = (this.LangName != null) ? this.LangName.CompareTo(((Lang)obj).LangName) : -1;
                    break;
                case "Icon":
                    relativeValue = (this.Icon != null) ? this.Icon.CompareTo(((Lang)obj).Icon) : -1;
                    break;
                case "PubDate":
                    relativeValue = (this.PubDate != null) ? this.PubDate.CompareTo(((Lang)obj).PubDate) : -1;
                    break;
                case "Desc":
                    relativeValue = (this.Desc != null) ? this.Desc.CompareTo(((Lang)obj).Desc) : -1;
                    break;
                case "Flag":
                    relativeValue = (this.Flag != null) ? this.Flag.CompareTo(((Lang)obj).Flag) : -1;
                    break;
                default:
                    goto case "Id";
            }
            if (Lang.SortDirection == SortDirection.Ascending)
                relativeValue *= -1;
            return relativeValue;
        }
        #endregion
    }

    #endregion
}
